<?php
    $check = 0;
    if(trim($_POST['c_no'])!=''){
        $c_no = addslashes(trim($_POST['c_no']));
        $c_id = $_POST['c_id'];
        $cc_id = $_POST['cc_id'];
        $result = $db->Execute("SELECT c_id FROM customer WHERE cc_id='$cc_id' AND c_no=$c_no AND c_id!=$c_id");
        if($result->RowCount()>0){
            $msg = 'Customer No. นี้ถูกใช้ไปแล้ว';
        }else{
            $data = array();
            foreach($_POST as $k=>$v){
                if($v=='on'){
                    $data[$k] = 1;
                }else{
                    $data[$k] = $v;
                }
            }
            
            $result = $db->AutoExecute('customer', $data, 'UPDATE' , "c_id=$c_id");
            
            if($result){
                $msg = 'บันทึกข้อมูลเรียบร้อยแล้ว';
                $check = 1;
            }else{
                $msg = 'ไม่สามารถบันทึกข้อมูลได้';
            }
        }
    }else{
        $msg = 'กรุณากรอก Customer No.';
    }
?>

<?php
    include('header.php');
    include('submenu.php');
?>
<div class="grid_18" id="contents">
    <div id="query_result">
    <?php
        alert($msg);
    ?>
    </div>
</div><!-- end .grid_18 -->
<div class="clear">&nbsp;</div>
<?php
    include('footer.php');
?>
<script>
    $(document).ready(function(){
        if(<?php echo $check; ?>==0){
            $('#ajax_loader',window.parent.document).css('display','none');
        }else{
            top.window.location = '?m=customer&s=customer';
        }
    });
</script>